﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;
using System.Xml;
using TomanuExtensions;
using System.Globalization;
using AmiEmuLib.Host.HostSound;
using AmiEmuLib.AmigaConfiguration;
using AmiEmuLib.AmigaConfiguration.ChipsetConfig;

namespace AmiEmuLib.Configuration.AmigaAudioConfig
{
	public class AmigaAudioBlep
	{
        public const int AUDIO_BLEP_LENGTH = 2048;

        public readonly AmigaAudioBlepFilterType Filter;
        public readonly HostAudioSamplingRate SamplingRate;
        public readonly ReadOnlyCollection<double> Blep;
        public readonly AmigaModel Model;
        public readonly TVMode TVMode;
        public readonly string Name;

        public AmigaAudioBlep(XmlReader a_reader)
        {
            Filter = a_reader.GetAttributeEnum<AmigaAudioBlepFilterType>("Filter");
            SamplingRate = a_reader.GetAttributeEnum<HostAudioSamplingRate>("SamplingRate");
            Model = a_reader.GetAttributeEnum<AmigaModel>("Model");
            Name = a_reader.GetAttribute("Name");
            TVMode = a_reader.GetAttributeEnum<TVMode>("TVMode");

            a_reader.ReadStartElement(GetType().Name);

            string values1 = a_reader.ReadContentAsString().Replace(Environment.NewLine, "");
            var values2 = values1.Split(",");
            Blep = values2.Select(s => Double.Parse(s, CultureInfo.InvariantCulture)).ToList().AsReadOnly();

            a_reader.ReadEndElement();
        }

        public override string ToString()
        {
            return String.Format("AmigaModel: {0}; TVMode: {1} Name: {2}; Filter: {3}; FQ: {4}", 
                Model, TVMode, Name, Filter, SamplingRate);
        }
	}
}
